package com.ruoyi.web.controller.tool;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.RecordTable;
import com.ruoyi.system.service.IRecordTableService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 业务表管理Controller
 *
 * @author ruoyi
 * @date 2022-10-03
 */
@RestController
@RequestMapping("/tool/table")
public class RecordTableController extends BaseController {
    @Autowired
    private IRecordTableService recordTableService;

/**
 * 查询业务表管理列表
 */
@GetMapping("/list")
    public TableDataInfo list(RecordTable recordTable) {
        startPage();
        List<RecordTable> list = recordTableService.selectRecordTableList(recordTable);
        return getDataTable(list);
    }

    /**
     * 导出业务表管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:table:export')")
    @Log(title = "业务表管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, RecordTable recordTable) {
        List<RecordTable> list = recordTableService.selectRecordTableList(recordTable);
        ExcelUtil<RecordTable> util = new ExcelUtil<RecordTable>(RecordTable. class);
        util.exportExcel(response, list, "业务表管理数据");
    }

    /**
     * 获取业务表管理详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(recordTableService.selectRecordTableById(id));
    }

    /**
     * 新增业务表管理
     */
    @PreAuthorize("@ss.hasPermi('system:table:add')")
    @Log(title = "业务表管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody RecordTable recordTable) {
        return toAjax(recordTableService.insertRecordTable(recordTable));
    }

    /**
     * 修改业务表管理
     */
    @PreAuthorize("@ss.hasPermi('system:table:edit')")
    @Log(title = "业务表管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody RecordTable recordTable) {
        return toAjax(recordTableService.updateRecordTable(recordTable));
    }

    /**
     * 删除业务表管理
     */
//    @PreAuthorize("@ss.hasPermi('system:table:remove')")
//    @Log(title = "业务表管理", businessType = BusinessType.DELETE)
//    @DeleteMapping("/{ids}")
//    public AjaxResult remove(@PathVariable Long[] ids) {
//        return toAjax(recordTableService.deleteRecordTableByIds(ids));
//    }

    /**
     * 删除业务表管理
     */
    @PreAuthorize("@ss.hasPermi('system:table:remove')")
    @Log(title = "业务表管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{id}")
    public AjaxResult delete(@PathVariable Long id) {
        return toAjax(recordTableService.deleteRecordTableById(id));
    }
}
